﻿using System;
using System.Threading;
using static System.Console;
using static System.Threading.Thread;

namespace Chapter1.Recipe4
{
    class Program
    {
        static void Main(string[] args)
        {
            WriteLine("Starting Program...");
            Thread t = new Thread(PrintNumberWithDelay);
            t.Start();
            Thread.Sleep(TimeSpan.FromSeconds(6));
            //向线程t 注入ThreadAbortException方法，导致线程被终结
            t.Abort();
            WriteLine("A thread has been aborted");
            Thread t1 = new Thread(PrintNumbers);
            t1.Start();
            PrintNumbers();
        }

        static void PrintNumberWithDelay()
        {
            WriteLine("Starting...");
            for (int i = 1; i < 10; i++)
            {
                Sleep(TimeSpan.FromSeconds(2));
                WriteLine(i);
            }
        }
        static void PrintNumbers()
        {
            WriteLine("Starting...");
            for (int i = 1; i < 10; i++)
            {
                WriteLine(i);
            }
        }
    }
}
